local s4__huanshi = fk.CreateSkill {
  name = "s4__huanshi",
}

Fk:loadTranslationTable {
  ["s4__huanshi"] = "缓释",
  [":s4__huanshi"] = "当己方角色的判定牌生效前，你可以打出一张牌代替之。",

  ["#s4__huanshi-invoke"] = "缓释：是否打出一张牌修改 %dest 的判定牌？",

  ["$s4__huanshi1"] = "缓乐之危急，释兵之困顿。",
  ["$s4__huanshi2"] = "尽死生之力，保友邦之安。",
}

s4__huanshi:addEffect(fk.AskForRetrial, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(s4__huanshi.name) and target:isFriend(player) and
        not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local ids = table.filter(table.connect(player:getHandlyIds(), player:getCardIds("e")), function(id)
      return not player:prohibitResponse(Fk:getCardById(id))
    end)
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      skill_name = s4__huanshi.name,
      include_equip = true,
      pattern = tostring(Exppattern { id = ids }),
      prompt = "#s4__huanshi-invoke::" .. target.id,
      cancelable = true,
    })
    if #cards > 0 then
      event:setCostData(self, { cards = cards })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:changeJudge {
      card = Fk:getCardById(event:getCostData(self).cards[1]),
      player = player,
      data = data,
      skillName = s4__huanshi.name,
      response = true,
    }
  end,
})

return s4__huanshi
